<template>
  <div>
    <van-nav-bar
      title="考勤统计"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <div style="height: 750px;">
      <van-form @submit="onSubmit">
        <van-field
          v-model="data.adtrtName"
          label="用印文件名"
          placeholder="请输入"
          :rules="[{ required: true, message: '用印文件名' }]"
        />
        <van-field
          v-model="data.adtrtCount"
          name="文件份数"
          label="文件份数"
          placeholder="请输入"
          :rules="[{ required: true, message: '文件份数' }]"
        />
        <van-cell is-link title="加盖印章类型" :value="data.ZhangType" @click="showPicker = true" size="large">
        </van-cell>
        <van-field
          v-model="data.adtrtReson"
          label="用印原因"
          placeholder="请输入"
          :rules="[{ required: true, message: '用印原因' }]"
        />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">
            提交
          </van-button>
        </div>
      </van-form>
    </div>
    <van-popup v-model="showPicker" position="bottom">
      <van-picker
        show-toolbar
        :columns="columns"
        @cancel="showPicker = false"
        @confirm="onConfirm"
      />
    </van-popup>

  </div>
</template>

<script>
  import {Toast} from "vant";
  import Administrative from "@/api/Administrative";

  export default {
    data() {
      return {
        value: '单程',
        showPicker: false,
        //<Option value="1">公章</Option>
        /*    <Option value="2">合同章</Option>
            <Option value="3">其他</Option>*/
        columns: ['公章', '合同章', '其他'],
        data: {
          adtrtName: '',
          adtrtCount: '',
          ZhangType: '公章',
          adtrtReson: '',
        },
        selfType:'',
      };
    },
    methods: {
      onClickLeft() {
        this.$router.push('/work')
      },
      onConfirm(value) {
        this.data.ZhangType = value;
        this.showPicker = false;
      },
      onSubmit() {
        Toast.loading({
          message: '提交中...',
          forbidClick: true,
        });

        const changeType = this.data.ZhangType;
        /*  columns: ['公章', '合同章','其他'],*/
        if (changeType === '公章') {
           this.selfType = '1';
        }else if (changeType === '公章'){
          this.selfType = '2';
        }else {
          this.selfType = '3';
        }
        Administrative.insertCarOrZang({
          userId: this.$store.getters.userInfo.userId,
          adtrtType: 3, //行政类型（1：物品领用，2：用车申请，3：永章申请）
          // status: 1 //审核状态（1：通过，2：未审核
          adtrtName: this.data.adtrtName,
          adtrtCount: this.data.adtrtCount,
          ZhangType:  this.selfType,
          adtrtReson: this.data.adtrtReson,

        })
          .then(res => {
            // 返回数据
            Toast.success('提交成功');
            this.data.adtrtName = '';
            this.data.adtrtCount = '';
            this.data.adtrtReson = '';
          })
          .catch(err => {
            // 异常情况
          })
      },
    }
  }
</script>

<style scoped>

</style>
